<?php

namespace App\Http\Controllers\Api\Admin;

use App\Http\Controllers\Api\Controller;
use App\Http\Requests\Api\AdminuserRequest;
use App\Models\AdminUser;
use App\Transformers\AdminuserTransformer;


class AdminuserController extends Controller
{
    //
    public function store(AdminuserRequest $request, AdminUser $adminuser)
    {
            $adminuser->username = $request->username;
            $adminuser->password = bcrypt($request->password);
            $adminuser->save();

            return $this->response->array(['message'=>'添加成功'])->setStatusCode(201);
    }

    public function update(AdminUser $adminUser,AdminuserRequest $request){

        $adminUser->update($request->all());

            return $this->response->array(['message'=>'修改成功']);


    }

    public function destory(AdminUser $adminUser){
        $result=$adminUser->delete();
        if ($result){
            return $this->response->array(['message'=>'删除成功']);
        }else{
            return $this->response->array(['message'=>'删除失败']);
        }
    }

    public function list(AdminUser $adminUser){
       $result=$adminUser->get();
       if ($result){
           return $this->response->array($result);
       }else{
           return $this->response->array(['message'=>'查询失败']);
       }
    }
}
